package com.webcash.CNBoard.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.webcash.CNBoard.Model.Employee;
import com.webcash.CNBoard.Model.Team;

@Repository
public class EmployeeRepositoryImpl extends SqlSessionDaoSupport implements
		EmployeeRepository {

	public Employee selectEmployeeById(String id) {
		SqlSession session = getSqlSession();

		return session.selectOne("Employee.selectEmployeeById", id);
	}

	public List<Employee> selectDeptInEmployeeList(int deptNo) {
		// TODO Auto-generated method stub
		return null;
	}

	public Employee isValidPassword(String id, String password) {
		SqlSession session = getSqlSession();
		Map param = new HashMap();
		param.put("id", id);
		param.put("password", password);
		
		return session.selectOne("Employee.selectEmployeeByIdAndPw", param);
	}
	
	public void updateEmployeeAccountbyEmp(Employee emp){
		SqlSession session = getSqlSession();
		session.update("Employee.updateEmployeeAccountById", emp);
	}

	public void updateEmployeeAccountImgPathbyEmp(Employee emp) {
		SqlSession session = getSqlSession();
		session.update("Employee.updateEmployeeAccountImgPathByemp", emp);
	}

	public List<Employee> selectTeamMemberListbyDeptNoAndTeamNo(Employee emp) {
		SqlSession session = getSqlSession();
		return session.selectList("Employee.selectTeamMemberListbydeptNoAndTeamNo", emp);
	}

	public List<Employee> selectTeamMemberListbyDeptNoAndTeamNo(Team team) {
		SqlSession session = getSqlSession();
		return session.selectList("Employee.selectTeamMemberListbydeptNoAndTeamNo", team);
	}

	public Employee selectEmployeeByEmpNo(int empNo) {
		SqlSession session = getSqlSession();
		return session.selectOne("Employee.selectEmployeeByEmpNo", empNo);
	}

	public void insertEmployeeByEmp(Employee emp) {
		SqlSession session = getSqlSession();
		session.insert("Employee.insertEmployee", emp);
		
	}

	public List<Employee> selectAllEmployee() {
		SqlSession session  = getSqlSession();
		return session.selectList("Employee.selectAllEmployee");
	}

	public Team selectMyTeamInfoByTeamNoAndDeptNo(String teamNo, String deptNo) {
		SqlSession session = getSqlSession();
		
		Map param = new HashMap();
		param.put("teamNo", teamNo);
		param.put("deptNo", deptNo);
		return session.selectOne("Team.selectMyTeamInfoByTeamNoAndDeptNo", param);
	}
	
	

}
